package com.study.controller;

import com.study.pojo.User;
import com.study.service.UserService;
import com.study.utils.JwtHelper;
import com.study.utils.Result;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * description:进入的控制层
 */
@RestController
@RequestMapping("user")
@CrossOrigin // 解决跨域问题
public class UserController {

    @Autowired
    private UserService userService;

    @PostMapping("login")
    public Result login(@RequestBody User user){
        Result result =userService.login(user);
        return result;
    }
    @GetMapping("getUserInfo")
    public Result getUserInfo(@RequestHeader("token") String token){ //token: 前端传过来的token
        Result result = userService.getUserInfo(token);
        return result;
    }
    @PostMapping("checkUserName")
    public Result checkUserName(String username){ //param数据接收就不加@RequestBody了
        Result result = userService.checkUserName(username);
        return result;
    }
    @PostMapping("regist")
    public Result regist(@RequestBody User user){
        Result result = userService.regist(user);
        return result;
    }

    /**
     * 登录校验和保护
     * @param token
     * @return
     */
    @GetMapping("checkLogin")
    public Result checkLogin(@RequestHeader String token){
        Result result =userService.checkLogin(token);
        return result;
    }
}
